﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

namespace JEng_Mark_1.SceneObject.SceneGraph
{
    public class JNode
    {
        protected JNodeList _nodes;

        /// <summary>
        /// Get the list of child nodes of this node
        /// </summary>
        public JNodeList Nodes { get { return _nodes; } }

        /// <summary>
        /// Create a new empty node
        /// </summary>
        public JNode()
        {
            _nodes = new JNodeList();
        }

        /// <summary>
        /// Add a child node to this node
        /// </summary>
        /// <param name="newNode">Child node to add</param>
        public void AddNode(JNode newNode)
        {
            _nodes.Add(newNode);
        }

        /// <summary>
        /// Update all child nodes of this node
        /// </summary>
        public virtual void Update()
        {
            _nodes.ForEach(delegate(JNode node)
            {
                node.Update();
            });
        }

        /// <summary>
        /// Tell all child nodes to unload their content
        /// </summary>
        public virtual void UnloadContent()
        {
            _nodes.ForEach(
                delegate(JNode node)
                {
                    node.UnloadContent();
                });
            _nodes.Clear();
        }

        /// <summary>
        /// 
        /// tell all child nodes to load their content
        /// </summary>
        public virtual void LoadContent()
        {
            _nodes.ForEach(
                delegate(JNode node)
                {
                    node.LoadContent();
                }
            );
        }

        /// <summary>
        /// Tell all child nodes to draw themselves
        /// </summary>
        /// <param name="gameTime">Timing snapshot</param>
        public virtual void Draw(GameTime gameTime)
        {
            _nodes.ForEach(
                delegate(JNode node)
                {
                    node.Draw(gameTime);
                });
        }
    }
}
